﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Wicresoft.SelfService.DAL;
using Wicresoft.SelfService.Portal.Models;
using System.Data;
using Oracle.DataAccess.Client;

namespace Wicresoft.SelfService.Portal.Service
{
    public class UserAndRoleInfo
    {
        OracleDataAccess oracle = new OracleDataAccess();
        private const string sqlstep = "select n.AccountID,n.UserName,n.Company,n.DEPT,n.Position,n.Phone,m.RoleID,m.IsAdmin from accountcopy n inner join userrolerelationship m on n.ACCOUNTID=m.ACCOUNTID where n.company='宁德市烟草专卖局' and roleid=";
        
        public List<UserRoleRelationshipModel> GetUserRoleRelationshipByRoleID(int RoleID) 
        {
            string sql = sqlstep + RoleID;
            DataTable ret = oracle.ExecuteFillToDataTable(sql);
            //var ret = OracleHelper.ExecuteDataTable(sql);
            UserRoleRelationshipModel user = new UserRoleRelationshipModel();
            List<UserRoleRelationshipModel> userList = new List<UserRoleRelationshipModel>();
            foreach (DataRow dr in ret.Rows) 
            {
                user.AccountID = dr["AccountID"].ToString();
                user.Company = dr["Company"].ToString();
                user.DEPT = dr["DEPT"].ToString();
                user.IsAdmin = Convert.ToInt32(dr["IsAdmin"]);
                user.Phone = dr["Phone"].ToString();
                user.Position = dr["Position"].ToString();
                user.RoleID = Convert.ToInt32(dr["RoleID"]);
                user.UserName = dr["UserName"].ToString();
                userList.Add(user);
            }
            return userList;
        }

    }
}